
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import tech.aistar.entity.Answer;
import tech.aistar.entity.Comment;
import tech.aistar.entity.UserInfo;
import tech.aistar.service.center.IUserInfoService;
import tech.aistar.service.collecte.ICollecteService;
import tech.aistar.service.comment.IAnswerService;
import tech.aistar.service.comment.ICommentService;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2019/10/2 0002.
 */
@Controller
@RequestMapping("/comment")
@SuppressWarnings("all")

public class CommentController {
    @Autowired
    private ICommentService commentService;

    @Autowired
    private IAnswerService answerService;

    @Autowired
    private ICollecteService collecteService;

    @Autowired
    private IUserInfoService userInfoService;


    @RequestMapping("/people")
    public String peoples(Model model, Answer answer,Integer id,HttpServletRequest request,HttpSession session){
        //评论
        List<Comment> commentList = commentService.comFindser(2);
//        List<Comment> commentList = commentService.comCounts(id);
                //获取评论人的id
        List<UserInfo> userInfos = new ArrayList<>();

        for (int i = 0; i < commentList.size(); i++) {
            System.out.println(commentList.get(i).getUserinfoId());
            //获取userinfoId 评论的姓名
            UserInfo userInfo = userInfoService.findById(commentList.get(i).getUserinfoId());
            userInfo.setId(commentList.get(i).getUserinfoId());
            userInfos.add(userInfo);
        }

        Integer userinfo4 = (Integer) session.getAttribute("userinfoId");

        List<Answer> answer1 = answerService.userId(userinfo4);

        //放入作用域
        model.addAttribute("answer1",answer1);
        model.addAttribute("commentList",commentList);
        model.addAttribute("userInfos",userInfos);

        return "redirect:/center/list";

    }


}